package de.hsma.srn.view.components;

import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;

public class MyListItemCellRenderer extends JPanel implements ListCellRenderer {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1296952208938922001L;

	private JLabel mLabel;

	public MyListItemCellRenderer() {
		super(new FlowLayout(FlowLayout.LEFT));

		setOpaque(true);

		mLabel = new JLabel();
		mLabel.setOpaque(true);
		add(mLabel);
	}

	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean hasFocus) {

		mLabel.setEnabled(list.isEnabled());
		mLabel.setIcon(((KeysListItem) value).getIcon());
		mLabel.setText(((KeysListItem) value).getText());

		if (isSelected) {
			setBackground(Color.LIGHT_GRAY);
		} else {
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		}

		return this;
	}

}
